classdef Neuron < handle
        
    properties (GetAccess = public, SetAccess = private)
        % value passed when activated
        ImpulseValue
        
        % Actual neuron charge
        ChargeValue = 0
        
        % all parameters
        Parameters
        
        % axonal synapses
        Synapses
    end
    
    methods
        % Neuron state update function. Should be called from the network
        % manager
        function [ret] = Update(obj)            
            ret = 0;
            % determine if we activate the neuron
            if obj.ChargeValue >= obj.Parameters.ActivationThreshold
                obj.ActivateAxon();
                ret = 1;
            else
                % decay the charge value
                obj.Rest();
            end                        
        end
        
        % Function used to decay the charge value
        function Rest(obj)
            
            %---------TO-DO---------------
            obj.ChargeValue = obj.ChargeValue - 0.1;
            if(obj.ChargeValue <= 0)
                obj.ChargeValue = 0;
            end
            %-----------------------------
            
        end
        
        % neuron receives charge from dendrite by using this function
        function ReceiveCharge(obj, value)
            obj.ChargeValue = obj.ChargeValue + value;
        end
        
        % Neuron activation function. Should be called from the Update
        % function
        function ActivateAxon(obj)
            for i=1:length(obj.Synapses)
                obj.Synapses(i).Activate(obj.ImpulseValue);
            end
            
            %---------TO-DO---------------
            obj.ChargeValue = 0;
            %-----------------------------
        end
        
        function AddSynapse(obj, synapse)
            obj.Synapses = [obj.Synapses, synapse];
        end
        
        % constructor
        function ret = Neuron(parameters, impulseValue)
            if nargin > 0
                ret.Parameters = parameters;
                ret.ImpulseValue = impulseValue;
            end
        end
        
    end
    
end

